package com.excilys.model;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;

import org.joda.time.DateTime;

/**
 * POJO Transfer transaction between two accounts.
 * 
 * @author excilys dev : YA
 * @version 1.0
 * 
 */
@SuppressWarnings("serial")
@Entity
public class TransactionTransfer extends Transaction {

	@ManyToOne
	private Account transferAccount; // transfer target

	// ------------------------------------------------------------
	// ------------------------------------------------------------
	// ------------------------------------------------------------

	public TransactionTransfer() {
		this.transactionType = TransactionType.TRANSFER;
	}

	public TransactionTransfer(double transactionAmount, DateTime transactionDate, Account transactionAccount, Account transferAccount) {
		super(transactionAmount, transactionDate, transactionAccount);
		this.transferAccount = transferAccount;
		this.transactionType = TransactionType.TRANSFER;
	}

	@Override
	public String toString() {
		String result = "TransactionId = " + transactionId + "  / TransactionAmount = " + transactionAmount + " / TransactionAccount = " + transactionAccount
				+ " / TransactionDate = " + transactionDate + " / TransferAccount = " + transferAccount;
		return result;
	}

	// ------------------------------------------------------------
	// ------------------------------------------------------------
	// ------------------------------------------------------------

	@Override
	public String printLabel() {
		return transferAccount.getAccountName();
	}

	// ------------------------------------------------------------
	// ------------------------------------------------------------
	// ------------------------------------------------------------

	public Account getTransferAccount() {
		return transferAccount;
	}

	public void setTransferAccount(Account transferAccount) {
		this.transferAccount = transferAccount;
	}

	@Override
	public int hashCode() {
		int result = 7;
		final int multiplier = 17;
		result = multiplier * result + (transferAccount == null ? 0 : transferAccount.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (obj instanceof TransactionTransfer) {
			TransactionTransfer other = (TransactionTransfer) obj;

			if (transferAccount != other.transferAccount) {
				if (transferAccount == null || !transferAccount.equals(other.transferAccount))
					return false;
			}
			return true;
		}
		return false;
	}

}
